﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NearForums.Validation;

namespace NearForums
{
    public class AdminMenu:Entity, IAccessRightContainer
    {
        public AdminMenu()
		{
			PostAccessRole = UserRole.Admin;
		}

        public int Id { get; set; }

        [RequireField]
        [Length(20)]
        public string MenuName
        {
            get;
            set;
        }
        /// <summary>
        /// 排序
        /// </summary>
        [RequireField]
        public int Sort
        {
            get;
            set;    
        }
        /// <summary>
        /// 上级ID
        /// </summary>
        [RequireField]
        public int leaveId { get; set; }

        #region IAccessRightContainer Members
        /// <summary>
        /// Minimal role to view this forum and its posts
        /// </summary>
        public UserRole? ReadAccessRole
        {
            get;
            set;
        }

        /// <summary>
        /// 在这个版面发表主题的最低的角色
        /// </summary>
        [PostGreaterThanReadRights]
        public UserRole PostAccessRole
        {
            get;
            set;
        }

        /// <summary>
        /// Determines if with the role supplied has access to post in this forum
        /// </summary>
        /// <returns></returns>
        public bool HasPostAccess(UserRole? userRole)
        {
            if (userRole >= PostAccessRole)
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// Determines if with the role supplied has access to read this forum
        /// </summary>
        /// <returns></returns>
        public bool HasReadAccess(UserRole? userRole)
        {
            if (ReadAccessRole == null || userRole >= ReadAccessRole)
            {
                return true;
            }
            return false;
        }
        #endregion
    }
}
